<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>学员管理|私教预约系统</title>
    <link href="../bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="../css/styles.css">
    <style type="text/css">

        p{
            font-family: tahoma,geneva,sans-serif;
            font-size: 24px;
            text-align: center;
        }
        table{
            margin-top: 30px;
        }
    </style>

</head>
<body>

<h3 class="col-sm-offset-5"><span class="label label-default">选课学生浏览</span></h3>

<div class="col-sm-4 col-sm-offset-10">
    <select class = "selectpicker" id = "inputCourseId" title="请选择" onclick="sort()">

    </select>
</div>


<div id="container">
    <div class="col-xl-10">
        <table class="table table-bordered table-striped table-hover">
            <thead>
            <tr>
                <td>#</td>
                <td>学生姓名</td>
                <td>性别</td>
                <td>年龄</td>
                <td>联系方式</td>
                <td>操作</td>
            </tr>
            </thead>
            <tbody id="tbody">

            </tbody>
        </table>
    </div>
</div>
</body>
<script src="../jquery/jquery-3.4.1.min.js"></script>
<script src="../bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function(){

        let currentTrainerPhone = $.cookie("trainerphone");

        jQuery.post("/getCourseListByTrainerPhone", {"trainerPhone": currentTrainerPhone}, function(rst){//处理响应的结果

            for (let id = 0; id < rst.length; ++id){
                jQuery("#inputCourseId").append("<option value='"+rst[id].courseId+"'>" + rst[id].courseName + "</option>");
            }

            let sortIdExit = document.cookie.indexOf("showStudentOfCourseId");

            if (sortIdExit === -1)
            {
                let sortId = 1;
                $.cookie('showStudentOfCourseId', sortId);
            }

            let currentShowStudentOfCourseId = $.cookie("showStudentOfCourseId");

            $("#inputCourseId").val(currentShowStudentOfCourseId);

            jQuery.post("/getStudentListByCourseId", {"courseId": currentShowStudentOfCourseId}, function(rst){//处理响应的结果
                writeHTML(rst);
            },"json");// 表示返回数据的格式

        },"json");//表示返回数据的格式

    });

    function writeHTML(rst){
        let body="";
        for(let i = 0; i < rst.length; i++)
        {
            let json = rst[i];//{"#":1, "课程名": "教练"： ,"开课时间": , "课程类型": ，"操作"： }

            body += "<tr>";
            body += "<td>" + (i + 1) + "</td>";
            body += "<td>" + json.userNickname + "</td>";
            body += "<td>" + json.userSex + "</td>";
            body += "<td>" + json.userAge + "</td>";
            body += "<td>" + json.userPhone + "</td>";
            body += "<td>";
            body += "<a href='#' onclick='sendMessage(\""+json.userId+"\")'>私信</a>";
            body += "</td>"
            body += "</tr>";
        }
        jQuery("#tbody").html(body);
    }

    $("#inputCourseId").click(function (){

        setTimeout("temp()", 2000);

    })

    function temp(){
        let options = $("#inputCourseId option:selected");
        let id = options.val();
        $.removeCookie("showStudentOfCourseId", {path: '/'});
        $.cookie("showStudentOfCourseId", id);
        window.location.reload();
    }


    function sendMessage(userId){
        // $.cookie('currentTrainerPhone', phone);
        // window.location.replace("trainerDetails.html");
    }

</script>
</html>